package Aim_at_Offer;
/*
 *  Author: Ksxy
 *  Date: 2018/3/25
 *  Version: 1.0
 *  Description: 请实现一个函数，将一个字符串中的空格替换成“%20”。例如，当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
 */

public class BlankSpaceReplace {
    public String replaceSpace(StringBuffer str) {
        char[] charArray = str.toString().toCharArray();
        StringBuilder sb = new StringBuilder();
        int len = charArray.length;
        for(int i=0; i < len; i++){
            if(charArray[i] == ' '){
                sb.append("%20");
            }else {
                sb.append(charArray[i]);
            }
        }
        return sb.toString();
    }
}
